﻿#ifndef LDUDIAGPRECOND_HPP
#define LDUDIAGPRECOND_HPP

#include "unapMatrix.hpp"
#include "unapPreconditioner.hpp"

namespace UNAP {

/// \brief diagonal Preconditioner in LDU type
/// also seen as Jacobi Preconditioner
template <typename Cmpt>
class DiagPrecond : public Preconditioner<Cmpt> {
 private:
  /// \brief the reciprocal diagonal
  Vector<Cmpt> rD_;

 public:
  /// \brief constructor
  /// \param A matrix input
  DiagPrecond(const Matrix<Cmpt> &A);

  /// \brief destructor
  virtual ~DiagPrecond() {}

  /// \brief return wA the preconditioned form of residual rA
  /// \param w resulting vector, preconditioned by rA
  /// \param r Preconditioner vector
  virtual void precondition(Vector<Cmpt> &w, const Vector<Cmpt> &r) const;

  /// \brief return the reciprocal diagonal
  virtual const Vector<Cmpt> &rD() const { return rD_; }
};

}  // namespace UNAP

#endif  // LDUDIAGPRECOND_HPP
